﻿/* 10. Write a program to calculate the sum (with accuracy of 0.001): 1 + 1/2 - 1/3 + 1/4 - 1/5 + ... */

using System;

public class SumWithAccuracy 
{
    public static void Main()
    {
        decimal accuracy = 0.001M;
        decimal oldSum = 0M;
        decimal sum = 1M;
        int counter = 2;
        int sign = 1;

        while (Math.Abs(sum - oldSum) >= accuracy)
        {
            oldSum = sum;
            sum += (1M / counter) * sign;
            counter++;
            sign = -sign;
        }

        Console.WriteLine("The sum with accuracy {0} is {1:0.000}", accuracy, oldSum);
    }
}